﻿using System;
using System.Globalization;
using System.IO;
using UnityEngine;

namespace Logic.Global
{
    public class AppConst
    {
        public static string CurVersion => "1.0.0";

        /// 当前渠道
        public static string ChannelMacro => Const.GoogleAndroid;

        /// 当前开发环境  开发模式 or 生产模式
        public static Environment Environment => Environment.Dev;

        /// <summary>
        /// 资源服务器路径
        /// </summary>
        public static string AssetServerUrl
        {
            get
            {
                if (IsAndroid || IsIOS)
                    return $"http://c1b.tapque.com/Innovate/CYFrame/{Environment}/{ChannelMacro}/V{CurVersion}";
                else
                    return $"http://c1a.tapque.com/Innovate/CYFrame/{Environment}/{ChannelMacro}/V{CurVersion}";
            }
        }

        /// <summary>
        /// 资源缓存路径,带 /
        /// </summary>
        /// <param name="loadName"></param>
        /// <returns></returns>
        public static string AssetCachePath(string loadName)
        {
            string cachePath;
            if (Application.platform is RuntimePlatform.Android or RuntimePlatform.IPhonePlayer)
            {
                cachePath = Application.persistentDataPath + "/Download/";
            }
            else
            {
                cachePath = Application.streamingAssetsPath + "/Download/";
            }

            cachePath += loadName;
            string dirPth = Path.GetDirectoryName(cachePath);
            if (!Directory.Exists(dirPth)) Directory.CreateDirectory(dirPth);
            return cachePath;
        }

        public static bool IsAndroid => ChannelMacro.Equals(Const.Android);

        public static bool IsGoogleAndroid => ChannelMacro.Equals(Const.GoogleAndroid);

        public static bool IsHaiWaiIOS => ChannelMacro.Equals(Const.HaiWaiIOS);

        public static bool IsIOS => ChannelMacro.Equals(Const.iOS);

        public static readonly CultureInfo NormalCultureInfo = CultureInfo.GetCultureInfo("en-US");
    }


    public enum Environment
    {
        Dev,
        Production,
    }
}